package com.geovis.emergency.spd.util;

import cn.hutool.http.HttpGlobalConfig;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import com.geovis.emergency.spd.biz.iflytek.config.IflytekConfig;
import com.geovis.emergency.spd.redis.RedisUtil;
import com.google.common.collect.Maps;
import lombok.extern.log4j.Log4j2;

import java.util.Map;

/**
 * <p>
 *
 * </p>
 *
 * @author Lonsho
 * @version 1.0
 * @date 2022/8/24
 */
@Log4j2
public class MyHttpUtil extends HttpUtil {
//    private static String TOKEN = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX25hbWUiOiJhaW1pbmRhZG1pbiIsInNjb3BlIjpbIm9wZW5pZCJdLCJleHAiOjE2NjE0MTM4NDEsImlhdCI6MTY2MTMyNzQ0MSwiYXV0aG9yaXRpZXMiOlsiUk9MRV9BRE1JTl9YTVJLRVIiLCJST0xFX0FJTUlORF9BRE1JTklTVFJBVE9SIl0sImp0aSI6ImY3N2UyYmRjLWEzODUtNDU1YS05NmRmLTQwMTU1YTQ4ZjE2OSIsImNsaWVudF9pZCI6IndlYl9hcHAifQ.RTIG_hW6nqJtmdLfg46JuTSbixydlKhO8Z-SRT5BoaGTSSjqSoTW314UpmaZtGPFs8WA_0ZbqGoPKjdv-eAzS8-juSeO00E1_G7z2dxqrat9Pn11sd6SKuHtplg_L88EsbWh4tqPQbdawsLB8j84ziZZEigkI_-mc4Drp5t_TM7FxuzgG2VbKQPkKuMt1J_BM6JHJdS17GdsQi6zLzFpKdlW2kaJtNWs6bNPbqgoURccN2aA8R0WYTKQcSvR9EM-_NJQNSChFF2IJq3Vz5lq-Pbre61AQZpIwmCeHIBOK2jwHv4a6ip5quhKvdlbNbSosLpZJXvxQ5yelQiSyUdNCA";


    public static String post(String urlString, Map<String, Object> paramMap) {
        String TOKEN = IflytekConfig.AUTH_TOKEN();
        return HttpRequest.post(urlString).form(paramMap).auth(TOKEN).timeout(HttpGlobalConfig.getTimeout()).execute().body();
    }
    public static String get(String urlString, Map<String, Object> paramMap) {
        String TOKEN = IflytekConfig.AUTH_TOKEN();
        return HttpRequest.get(urlString).form(paramMap).auth(TOKEN).timeout(HttpGlobalConfig.getTimeout()).execute().body();
    }
    public static String put(String urlString, String body) {
        String TOKEN = IflytekConfig.AUTH_TOKEN();
        return HttpRequest.put(urlString).auth(TOKEN).body(body).timeout(HttpGlobalConfig.getTimeout()).execute().body();
    }

    public static String post(String urlString, String body) {
        log.warn("请求开始 {}",urlString);
        long startTime = System.currentTimeMillis();
        String TOKEN = IflytekConfig.AUTH_TOKEN();
        log.warn("请求参数 {}",body);
        String result = HttpRequest.post(urlString).auth(TOKEN).body(body).timeout(HttpGlobalConfig.getTimeout()).execute().body();
        log.warn("请求结果 {}",result);
        long endTime = System.currentTimeMillis();
        log.warn("请求结束，耗时 {}ms",endTime - startTime );
        return result;
    }
}
